import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore(
  'counter',
  () => {
    // 定义 state
    const count = ref(0)

    const info = ref({
      name: 'jack',
      age: 18,
      friend: 'rose',
    })

  // 定义 getters
  const double = computed(() => count.value * 2)

  // 定义 actions
  const increment = () => {
    count.value++
  }

  const decrement = () => {
    count.value--
  }

  const addAge = () => {
    info.value.age++
  }


  // 千万不要忘记这里要 return
  return { count, double, increment, decrement ,addAge,info}
},
{
  // unistorage: true,// 都保存
  unistorage: {
    key: 'doctor-info', // LocalStorage中的 key
    paths: ['count', 'info'], // 状态变量的属性名
  }, // 都保存
}
)